/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.stepforward.me;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

/**
 *
 * @author jfernan
 */
public class googleIntentDemo extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        // ToDo add your GUI initialization code here

        setContentView(R.layout.googleintent);


        Button button_geo=(Button)this.findViewById( R.id.button_geo);
        Button button_call=(Button)this.findViewById( R.id.button_call);
        Button button_site=(Button)this.findViewById( R.id.button_site);
        Button button_sms=(Button)this.findViewById( R.id.button_sms);
        Button button_email=(Button)this.findViewById( R.id.button_email);

        // open google maps at a given latitude and longitude

        button_geo.setOnClickListener( new OnClickListener(){

            public void onClick(View arg0) {
                EditText tlat=(EditText)findViewById( R.id.text_lat);
                EditText tlong=(EditText)findViewById( R.id.text_long);

                String geo="geo:"+tlat.getText().toString()+","+tlong.getText().toString();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(geo));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);

            }

        } );

        // dial one number

        button_call.setOnClickListener( new OnClickListener(){

            public void onClick(View arg0) {
                EditText tcall=(EditText)findViewById( R.id.text_phone);
                String phone= tcall.getText().toString();
                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:"+phone));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);

            }

        } );

        // open site

        button_site.setOnClickListener( new OnClickListener(){

            public void onClick(View arg0) {
               EditText tsite=(EditText)findViewById( R.id.text_site);
               String site= tsite.getText().toString();
                Intent intent = new Intent(Intent.ACTION_VIEW);

                intent.setData(Uri.parse(site));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);


            }

        } );


        // send SMS

      button_sms.setOnClickListener( new OnClickListener(){

            public void onClick(View arg0) {



                EditText tcall=(EditText)findViewById( R.id.text_phone);
                String phone= tcall.getText().toString();
                String mymessage="my first message";

                PendingIntent pi = PendingIntent.getActivity(googleIntentDemo.this, 0,
                  new Intent(googleIntentDemo.this, googleIntentDemo.class), 0);
                SmsManager sms = SmsManager.getDefault();
                sms.sendTextMessage(phone, null, mymessage, pi, null);
                
          
            }

        } );

        // send email



          button_email.setOnClickListener( new OnClickListener(){

            public void onClick(View arg0) {

                Intent emailIntent=new Intent(Intent.ACTION_SEND);
                String subject = "Hi!";
                String body = "hello from android....";
                //String extra[] = new String[]{"aaa@bbb.com"};

              //   String extra =  "aaa@bbb.com";

                emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{ "aaa@bbb.com"});
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
                emailIntent.putExtra(Intent.EXTRA_TEXT, body);

                // for the emulator
                emailIntent.setType("text/plain");

                // for real device
                //emailIntent.setType("message/rfc822");
                
                startActivity(emailIntent);

                
            }

        } );




   }

    

}
